//
//  TextPage.swift
//  PracticeDemo
//
//  Created by 顾浩然 on 2025/1/23.
//

import SwiftUI

struct TextPage: View {
    //设置时间格式化
    static let taskDateFormat: DateFormatter = {
        let formatter = DateFormatter()
        formatter.dateStyle = .long
        formatter.dateFormat = "yyyy-MM-dd HH:mm:ss"
        return formatter
    }()
    
    let dueDate = Date()
    
    var body: some View {
        VStack(
            spacing: 10
        ){
            Text("This is some longer text 11111111111111111111111111111111111111")
                //最大行数
                .lineLimit(2)
                //控件尺寸
                .frame(
                    width: 200
                )
                //调整省略号的位置到中间
                .truncationMode(.middle)
                //添加textSelection表示可复制
                .textSelection(.enabled)
            
            Text("This is custom text")
                //设置字体
                .font(.title)
                //尺寸
                .frame(
                    width: 300
                )
                //文字颜色
                .foregroundColor(Color.blue)
                //背景色
                .background(Color.cyan)
            
            Text("This is an extremely long text string that will never fit even the")
                .font(Font.title2)
                //设置多行文本的对齐方式
                .multilineTextAlignment(.leading)
                .frame(
                    width: 350
                )
                .background(Color.brown)
            
            //在文本里设置格式化
            Text("Task due date: \(dueDate , formatter: Self.taskDateFormat)")
            
            Text("SPACING")
                //字符间距
                .tracking(20)
            
            Text(Date().addingTimeInterval(600), style: .relative)
            
            Text("test")
                //强制大写
                .textCase(.uppercase)
            
            //显示文本+图标
            Label("your account" , systemImage: "person.crop.circle")
                .font(Font.title2)
                //设置标签显示方式
                .labelStyle(.iconOnly)
            
            //定义一个完全自定义的label
            Label {
                Text("Paul Hudson")
                    .foregroundColor(.primary)
                    .font(.title3)
                    .padding()
                    .background(Color.gray.opacity(0.2))
                    .clipShape(Capsule())
            } icon: {
                RoundedRectangle(cornerRadius: 10)
                    .fill(Color.blue)
                    .frame(width: 32, height: 32)
            }
            
            VStack{
                Text("this is test")
                Text("this is test")
            }
            .font(.title)
            //有文本但表示文本不重要，显示灰色的
            .redacted(reason: .placeholder)
            
            
        }.padding()
    }
}

struct TextPage_Previews: PreviewProvider {
    static var previews: some View {
        TextPage()
    }
}
